/*
 * 文件名: CalendarDialogCommon.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-XUJIAO001
 * 创建时间: 2011-12-29
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.widget.calendar.dialog;

import java.util.Calendar;

import android.content.Context;
import app.log.APPLog;
import app.widget.calendar.widget.OnWheelChangedListener;
import app.widget.calendar.widget.WheelView;
import app.widget.calendar.widget.adapter.DateNumericAdapter;


/**
 * @author EX-XUJIAO001
 * @date 2011-12-29
 * @version [Android PABank C01, @2011-12-29]
 * @description
 */
public class CalendarDialogCommon {
	/**o
	 * 月份数组
	 */
	public static final String[] MONTHS = new String[] { "1月", "2月", "3月",
			"4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
	/**
	 * 日前数组
	 */
	public static final String[] DAYS = new String[]{"1日","2日","3日","4日","5日","6日","7日","8日","9日","10日",
		"11日","12日","13日","14日","15日","16日","17日","18日","19日","20日","21日","22日","23日","24日","25日","26日","27日"
		,"28日","月末"
	};
	
	/**
	 * 上午下午
	 */
	public static final String[] AM_PM = new String[] { "上午", "下午" };
	/**
	 * 每
	 */
	public static final String[] PERS = new String[] { "每周", "每月", "每天" };
	/**
	 * 星期
	 */
	public static final String[] WEEKS = new String[] { "星期日", "星期一", "星期二",
			"星期三", "星期四", "星期五", "星期六" };
	/**
	 * 空白
	 */
	public static final String[] BLOCK = new String[] { "" };
	/**
	 * 每周 每月
	 */
	public static final String PER_W_M [] = new String[]{"每周", "每月"};

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 根据当前年的当前月更新 天数
	 * 
	 * @param context
	 *            上下文
	 * @param day
	 *            滚轮view
	 */
	public static void updateDays(Context context, WheelView day,Calendar calendar) {
		//Calendar calendar = Calendar.getInstance();
		int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		day.setViewAdapter(new DateNumericAdapter(context, 1, maxDays, calendar
				.get(Calendar.DAY_OF_MONTH) - 1, "日"));
		int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
		day.setCurrentItem(curDay - 1, true);
	}
	
	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * 
	 * @param context
	 *            上下文
	 * @param year
	 *            滚轮view
	 * @param month
	 *            滚轮view
	 * @param day
	 *            滚轮view
	 */
	public static void updateDays(Context context, WheelView year,int minYear,
			WheelView month, WheelView day) {
		Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.YEAR,
				minYear + year.getCurrentItem());
		calendar.set(Calendar.MONTH, month.getCurrentItem());
		APPLog.i("zbkc","year:"+(minYear + year.getCurrentItem())+"month:"+ month.getCurrentItem() );
		int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		day.setViewAdapter(new DateNumericAdapter(context, 1, maxDays, calendar
				.get(Calendar.DAY_OF_MONTH) - 1, "日"));
		int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
		day.setCurrentItem(curDay - 1, true);
	}
	
	
	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * 
	 * @param context
	 *            上下文
	 * @param month
	 *            滚轮view
	 * @param day
	 *            滚轮view
	 */
	public static void updateDays(Context context,
			WheelView month, WheelView day ,Calendar c) {
		Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.YEAR, c.get(Calendar.YEAR));
		calendar.set(Calendar.MONTH, month.getCurrentItem());

		int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		day.setViewAdapter(new DateNumericAdapter(context, 1, maxDays, calendar
				.get(Calendar.DAY_OF_MONTH) - 1, "日"));
		int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
		day.setCurrentItem(curDay - 1, true);
	}
	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 添加监听器
	 * @param listener 监听器
	 * @param views 滚动View
	 */
	public static void addChangeListener(OnWheelChangedListener listener,
			WheelView... views) {
		for (WheelView view : views) {
			view.addChangingListener(listener);
		}
	}
	
	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * @param data 需要轉換的數據
	 * @return String
	 */
	public static String convertZeroString(int data){
		String result = null;
		if(data > 9)
		{
			result = data+"";
		}else{
			result = "0"+data;
		}
		
		return result;
	}

}
